home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / term-source.lha / termScroll.c < prev    next >
C/C++ Source or Header  |  1995-07-01  |  32KB  |  1,657 lines

  1. /*
  2. **    termScroll.c
  3. **
  4. **    Support routines for optimized screen scrolling.
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. //#define WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  13.  
  14. VOID DebugShowScrollInfo(VOID);
  15.  
  16.     /* ScrollFrameUpdate(VOID):
  17.      *
  18.      *    Optimize the area to be scrolled by moving the top and
  19.      *    bottom lines as needed.
  20.      */
  21.  
  22. STATIC VOID __inline
  23. ScrollFrameUpdate(VOID)
  24. {
  25.     while(ScrollLineFirst < RasterHeight && !ScrollLines[ScrollLineFirst] . Width)
  26.         ScrollLineFirst++;
  27.  
  28.     while(ScrollLineLast > 0 && !ScrollLines[ScrollLineLast] . Width)
  29.         ScrollLineLast--;
  30. }
  31.  
  32.     /* ScrollLineRectFill():
  33.      *
  34.      *    Fill a rectangular portion of the window raster with the help
  35.      *    of the scrolling information.
  36.      */
  37.  
  38. VOID __regargs
  39. ScrollLineRectFill(struct RastPort *RPort,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY)
  40. {
  41. #ifdef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  42.     if(MinX < MaxX && MinY < MaxY)
  43.     {
  44.         MinX += WindowLeft;
  45.         MinY += WindowTop;
  46.         MaxX += WindowLeft;
  47.         MaxY += WindowTop;
  48.  
  49.         if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  50.             RectFill(RPort,MinX,MinY,MaxX,MaxY);
  51.         else
  52.         {
  53.             SetAPen(RPort,BgPen);
  54.             RectFill(RPort,MinX,MinY,MaxX,MaxY);
  55.             SetAPen(RPort,FgPen);
  56.         }
  57.     }
  58. #else
  59.     if(MinX < MaxX && MinY < MaxY)
  60.     {
  61.         WORD    Start,Stop;
  62.         WORD    BackPen;
  63.  
  64.         if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  65.             BackPen    = FgPen;
  66.         else
  67.             BackPen = BgPen;
  68.  
  69.         Start    = MinY / TextFontHeight;
  70.         Stop    = MaxY / TextFontHeight;
  71.  
  72.         if(BackPen)
  73.         {
  74.             if(UseMasking)
  75.             {
  76.                 WORD Mask = BackPen,i;
  77.  
  78.                 for(i = Start ; i <= Stop ; i++)
  79.                 {
  80.                     if(ScrollLines[i] . Width)
  81.                         Mask |= ScrollLines[i] . ColourMask;
  82.  
  83.                     ScrollLines[i] . Left        = 0;
  84.                     ScrollLines[i] . Right        = LastColumn + 1;
  85.                     ScrollLines[i] . Width        = TextFontWidth;
  86.                     ScrollLines[i] . ColourMask    = BackPen;
  87.                 }
  88.  
  89.                 SetMask(RPort,Mask);
  90.             }
  91.             else
  92.             {
  93.                 WORD i;
  94.  
  95.                 for(i = Start ; i <= Stop ; i++)
  96.                 {
  97.                     ScrollLines[i] . Left        = 0;
  98.                     ScrollLines[i] . Right        = LastColumn + 1;
  99.                     ScrollLines[i] . Width        = TextFontWidth;
  100.                     ScrollLines[i] . ColourMask    = BackPen;
  101.                 }
  102.             }
  103.  
  104.             if(Start < ScrollLineFirst)
  105.                 ScrollLineFirst = Start;
  106.  
  107.             if(Stop > ScrollLineLast)
  108.                 ScrollLineLast = Stop;
  109.  
  110.             ScrollFrameUpdate();
  111.         }
  112.         else
  113.         {
  114.             WORD    ScrollLineLeft    = 32767,
  115.                 ScrollLineRight    = 0,
  116.                 ScrollLineWidth    = 0;
  117.  
  118.             if(UseMasking)
  119.             {
  120.                 WORD Mask = 0,i;
  121.  
  122.                 for(i = Start ; i <= Stop ; i++)
  123.                 {
  124.                     if(ScrollLines[i] . Width)
  125.                     {
  126.                         if(ScrollLines[i] . Width > ScrollLineWidth)
  127.                             ScrollLineWidth = ScrollLines[i] . Width;
  128.  
  129.                         if(ScrollLines[i] . Left < ScrollLineLeft)
  130.                             ScrollLineLeft = ScrollLines[i] . Left;
  131.  
  132.                         if(ScrollLines[i] . Right > ScrollLineRight)
  133.                             ScrollLineRight = ScrollLines[i] . Right;
  134.  
  135.                         Mask |= ScrollLines[i] . ColourMask;
  136.                     }
  137.  
  138.                     ScrollLines[i] . Left        = 32767;
  139.                     ScrollLines[i] . Right        = 0;
  140.                     ScrollLines[i] . Width        = 0;
  141.                     ScrollLines[i] . ColourMask    = 0;
  142.                 }
  143.  
  144.                 if(Mask)
  145.                     SetMask(RPort,Mask);
  146.                 else
  147.                 {
  148.                     ScrollFrameUpdate();
  149.  
  150.                     return;
  151.                 }
  152.             }
  153.             else
  154.             {
  155.                 WORD i;
  156.  
  157.                 for(i = Start ; i <= Stop ; i++)
  158.                 {
  159.                     if(ScrollLines[i] . Width)
  160.                     {
  161.                         if(ScrollLines[i] . Width > ScrollLineWidth)
  162.                             ScrollLineWidth = ScrollLines[i] . Width;
  163.  
  164.                         if(ScrollLines[i] . Left < ScrollLineLeft)
  165.                             ScrollLineLeft = ScrollLines[i] . Left;
  166.  
  167.                         if(ScrollLines[i] . Right > ScrollLineRight)
  168.                             ScrollLineRight = ScrollLines[i] . Right;
  169.                     }
  170.  
  171.                     ScrollLines[i] . Left        = 32767;
  172.                     ScrollLines[i] . Right        = 0;
  173.                     ScrollLines[i] . Width        = 0;
  174.                     ScrollLines[i] . ColourMask    = 0;
  175.                 }
  176.             }
  177.  
  178.             if(ScrollLineWidth)
  179.             {
  180.                 WORD Temp;
  181.  
  182.                 if((Temp = ScrollLineLeft * ScrollLineWidth) > MinX)
  183.                     MinX = Temp;
  184.  
  185.                 if((Temp = ScrollLineRight * ScrollLineWidth) < MaxX)
  186.                     MaxX = Temp;
  187.  
  188.                 if(MaxX == ScrollLineRight)
  189.                     MaxX += FontRightExtend;    // Add margin for italics or boldface.
  190.  
  191.                 if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  192.                     MinY = Temp;
  193.  
  194.                 if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  195.                     MaxY = Temp;
  196.             }
  197.  
  198.             if(Start < ScrollLineFirst)
  199.                 ScrollLineFirst = Start;
  200.  
  201.             if(Stop > ScrollLineLast)
  202.                 ScrollLineLast = Stop;
  203.  
  204.             ScrollFrameUpdate();
  205.  
  206.             if(!ScrollLineWidth)
  207.                 return;
  208.         }
  209.  
  210.             /* And clear the raster. */
  211.  
  212.         if(MinX < MaxX && MinY < MaxY)
  213.         {
  214.             MinX += WindowLeft;
  215.             MinY += WindowTop;
  216.             MaxX += WindowLeft;
  217.             MaxY += WindowTop;
  218.  
  219.             if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  220.                 RectFill(RPort,MinX,MinY,MaxX,MaxY);
  221.             else
  222.             {
  223.                 SetAPen(RPort,BgPen);
  224.                 RectFill(RPort,MinX,MinY,MaxX,MaxY);
  225.                 SetAPen(RPort,FgPen);
  226.             }
  227.         }
  228.     }
  229.  
  230. //    DebugShowScrollInfo();
  231. #endif
  232. }
  233.  
  234. VOID __regargs
  235. ScrollLineRectFillNoTabChange(struct RastPort *RPort,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY)
  236. {
  237. #ifdef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  238.     if(MinX < MaxX && MinY < MaxY)
  239.     {
  240.         MinX += WindowLeft;
  241.         MinY += WindowTop;
  242.         MaxX += WindowLeft;
  243.         MaxY += WindowTop;
  244.  
  245.         if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  246.             RectFill(RPort,MinX,MinY,MaxX,MaxY);
  247.         else
  248.         {
  249.             SetAPen(RPort,BgPen);
  250.             RectFill(RPort,MinX,MinY,MaxX,MaxY);
  251.             SetAPen(RPort,FgPen);
  252.         }
  253.     }
  254. #else
  255.     if(MinX < MaxX && MinY < MaxY)
  256.     {
  257.         WORD    Start,Stop;
  258.         WORD    BackPen;
  259.  
  260.         if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  261.             BackPen    = FgPen;
  262.         else
  263.             BackPen = BgPen;
  264.  
  265.         Start    = MinY / TextFontHeight;
  266.         Stop    = MaxY / TextFontHeight;
  267.  
  268.         if(BackPen)
  269.         {
  270.             if(UseMasking)
  271.             {
  272.                 WORD Mask = BackPen,i;
  273.  
  274.                 for(i = Start ; i <= Stop ; i++)
  275.                 {
  276.                     if(ScrollLines[i] . Width)
  277.                         Mask |= ScrollLines[i] . ColourMask;
  278.                 }
  279.  
  280.                 SetMask(RPort,Mask);
  281.             }
  282.  
  283.             if(Start < ScrollLineFirst)
  284.                 ScrollLineFirst = Start;
  285.  
  286.             if(Stop > ScrollLineLast)
  287.                 ScrollLineLast = Stop;
  288.  
  289.             ScrollFrameUpdate();
  290.         }
  291.         else
  292.         {
  293.             WORD    ScrollLineLeft    = 32767,
  294.                 ScrollLineRight    = 0,
  295.                 ScrollLineWidth    = 0;
  296.  
  297.             if(UseMasking)
  298.             {
  299.                 WORD Mask = 0,i;
  300.  
  301.                 for(i = Start ; i <= Stop ; i++)
  302.                 {
  303.                     if(ScrollLines[i] . Width)
  304.                     {
  305.                         if(ScrollLines[i] . Width > ScrollLineWidth)
  306.                             ScrollLineWidth = ScrollLines[i] . Width;
  307.  
  308.                         if(ScrollLines[i] . Left < ScrollLineLeft)
  309.                             ScrollLineLeft = ScrollLines[i] . Left;
  310.  
  311.                         if(ScrollLines[i] . Right > ScrollLineRight)
  312.                             ScrollLineRight = ScrollLines[i] . Right;
  313.  
  314.                         Mask |= ScrollLines[i] . ColourMask;
  315.                     }
  316.                 }
  317.  
  318.                 if(Mask)
  319.                     SetMask(RPort,Mask);
  320.                 else
  321.                 {
  322.                     ScrollFrameUpdate();
  323.  
  324.                     return;
  325.                 }
  326.             }
  327.             else
  328.             {
  329.                 WORD i;
  330.  
  331.                 for(i = Start ; i <= Stop ; i++)
  332.                 {
  333.                     if(ScrollLines[i] . Width)
  334.                     {
  335.                         if(ScrollLines[i] . Width > ScrollLineWidth)
  336.                             ScrollLineWidth = ScrollLines[i] . Width;
  337.  
  338.                         if(ScrollLines[i] . Left < ScrollLineLeft)
  339.                             ScrollLineLeft = ScrollLines[i] . Left;
  340.  
  341.                         if(ScrollLines[i] . Right > ScrollLineRight)
  342.                             ScrollLineRight = ScrollLines[i] . Right;
  343.                     }
  344.                 }
  345.             }
  346.  
  347.             if(ScrollLineWidth)
  348.             {
  349.                 WORD Temp;
  350.  
  351.                 if((Temp = ScrollLineLeft * ScrollLineWidth) > MinX)
  352.                     MinX = Temp;
  353.  
  354.                 if((Temp = ScrollLineRight * ScrollLineWidth) < MaxX)
  355.                     MaxX = Temp;
  356.  
  357.                 if(MaxX == ScrollLineRight)
  358.                     MaxX += FontRightExtend;    // Add margin for italics or boldface.
  359.  
  360.                 if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  361.                     MinY = Temp;
  362.  
  363.                 if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  364.                     MaxY = Temp;
  365.             }
  366.  
  367.             if(Start < ScrollLineFirst)
  368.                 ScrollLineFirst = Start;
  369.  
  370.             if(Stop > ScrollLineLast)
  371.                 ScrollLineLast = Stop;
  372.  
  373.             ScrollFrameUpdate();
  374.  
  375.             if(!ScrollLineWidth)
  376.                 return;
  377.         }
  378.  
  379.             /* And clear the raster. */
  380.  
  381.         if(MinX < MaxX && MinY < MaxY)
  382.         {
  383.             MinX += WindowLeft;
  384.             MinY += WindowTop;
  385.             MaxX += WindowLeft;
  386.             MaxY += WindowTop;
  387.  
  388.             if(FgPen == BgPen || (Attributes & ATTR_INVERSE))
  389.                 RectFill(RPort,MinX,MinY,MaxX,MaxY);
  390.             else
  391.             {
  392.                 SetAPen(RPort,BgPen);
  393.                 RectFill(RPort,MinX,MinY,MaxX,MaxY);
  394.                 SetAPen(RPort,FgPen);
  395.             }
  396.         }
  397.     }
  398.  
  399. //    DebugShowScrollInfo();
  400. #endif
  401. }
  402.  
  403.     /* ScrollLineRaster():
  404.      *
  405.      *    Scroll the window raster with the help
  406.      *    of the scrolling information.
  407.      */
  408.  
  409. VOID __regargs
  410. ScrollLineRaster(struct RastPort *RPort,WORD DeltaX,WORD DeltaY,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY,BYTE Smooth)
  411. {
  412. #ifdef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  413.     if((DeltaX || DeltaY) && MinX < MaxX && MinY < MaxY)
  414.     {
  415.         MinX += WindowLeft;
  416.         MinY += WindowTop;
  417.         MaxX += WindowLeft;
  418.         MaxY += WindowTop;
  419.  
  420.         if(Smooth && DeltaY)
  421.         {
  422.             WORD Count,Direction,Extra;
  423.             BOOL ResetPen;
  424.  
  425.             if(DeltaY < 0)
  426.             {
  427.                 Count        = -DeltaY;
  428.                 Direction    = -2;
  429.             }
  430.             else
  431.             {
  432.                 Count        = DeltaY;
  433.                 Direction    = 2;
  434.             }
  435.  
  436.             Extra = Count & 1;
  437.             Count = Count / 2;
  438.  
  439.             if((Attributes & ATTR_INVERSE) && (FgPen != BgPen))
  440.             {
  441.                 SetBPen(RPort,FgPen);
  442.  
  443.                 ResetPen = TRUE;
  444.             }
  445.             else
  446.                 ResetPen = FALSE;
  447.  
  448.             while(Count--)
  449.             {
  450.                 WaitBlit();
  451.                 WaitTOF();
  452.                 ScrollRaster(RPort,0,Direction,MinX,MinY,MaxX,MaxY);
  453.             }
  454.  
  455.             if(Extra)
  456.             {
  457.                 WaitBlit();
  458.                 WaitTOF();
  459.                 ScrollRaster(RPort,0,Direction / 2,MinX,MinY,MaxX,MaxY);
  460.             }
  461.  
  462.             if(ResetPen)
  463.                 SetBPen(RPort,BgPen);
  464.         }
  465.         else
  466.         {
  467.             if((Attributes & ATTR_INVERSE) && (FgPen != BgPen))
  468.             {
  469.                 SetBPen(RPort,FgPen);
  470.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  471.                 SetBPen(RPort,BgPen);
  472.             }
  473.             else
  474.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  475.         }
  476.     }
  477. #else
  478.     if((DeltaX || DeltaY) && MinX < MaxX && MinY < MaxY)
  479.     {
  480.         WORD    Start,Stop;
  481.         WORD    BackPen;
  482.         BOOL    ResetPen;
  483.  
  484.         if((Attributes & ATTR_INVERSE) && (FgPen != BgPen))
  485.         {
  486.             SetBPen(RPort,FgPen);
  487.  
  488.             ResetPen    = TRUE;
  489.             BackPen        = FgPen;
  490.         }
  491.         else
  492.         {
  493.             ResetPen    = FALSE;
  494.             BackPen        = BgPen;
  495.         }
  496.  
  497.         Start    = MinY / TextFontHeight;
  498.         Stop    = MaxY / TextFontHeight;
  499.  
  500.         if(BackPen)
  501.         {
  502.             if(UseMasking)
  503.             {
  504.                 WORD i,Mask = BackPen;
  505.  
  506.                 for(i = Start ; i <= Stop ; i++)
  507.                 {
  508.                     if(ScrollLines[i] . Width)
  509.                         Mask |= ScrollLines[i] . ColourMask;
  510.                 }
  511.  
  512.                 SetMask(RPort,Mask);
  513.             }
  514.  
  515.             if(DeltaX)
  516.             {
  517.                 if(!ScrollLines[CursorY] . Width)
  518.                 {
  519.                     if(ResetPen)
  520.                         SetBPen(RPort,BgPen);
  521.  
  522.                     return;
  523.                 }
  524.                 else
  525.                 {
  526.                     ScrollLines[CursorY] . Left    = 0;
  527.                     ScrollLines[CursorY] . Right    = (LastPixel + 1) / ScrollLines[CursorY] . Width;
  528.  
  529.                     ScrollLines[CursorY] . ColourMask |= BackPen;
  530.                 }
  531.             }
  532.             else
  533.             {
  534.                 WORD i,Lines,Size;
  535.  
  536.                 Lines    = DeltaY / TextFontHeight;
  537.                 Size    = (MaxY - MinY + 1) / TextFontHeight;
  538.  
  539.                 if(Lines < 0)
  540.                 {
  541.                     Lines = -Lines;
  542.  
  543.                     if(Size <= Lines)
  544.                     {
  545.                         for(i = 0 ; i < Size ; i++)
  546.                         {
  547.                             ScrollLines[Start + i] . Left        = 0;
  548.                             ScrollLines[Start + i] . Right        = LastColumn + 1;
  549.                             ScrollLines[Start + i] . ColourMask    = BackPen;
  550.                             ScrollLines[Start + i] . Width        = TextFontWidth;
  551.                         }
  552.                     }
  553.                     else
  554.                     {
  555.                         WORD Offset = Size - Lines;
  556.  
  557.                         for(i = 1 ; i <= Offset ; i++)
  558.                             ScrollLines[Start + Size - i] = ScrollLines[Start + Size - (i + Lines)];
  559.  
  560.                         for(i = 0 ; i < Lines ; i++)
  561.                         {
  562.                             ScrollLines[Start + i] . Left        = 0;
  563.                             ScrollLines[Start + i] . Right        = LastColumn + 1;
  564.                             ScrollLines[Start + i] . ColourMask    = BackPen;
  565.                             ScrollLines[Start + i] . Width        = TextFontWidth;
  566.                         }
  567.                     }
  568.                 }
  569.                 else
  570.                 {
  571.                     if(Size <= Lines)
  572.                     {
  573.                         for(i = 0 ; i < Size ; i++)
  574.                         {
  575.                             ScrollLines[Start + i] . Left        = 0;
  576.                             ScrollLines[Start + i] . Right        = LastColumn + 1;
  577.                             ScrollLines[Start + i] . ColourMask    = BackPen;
  578.                             ScrollLines[Start + i] . Width        = TextFontWidth;
  579.                         }
  580.                     }
  581.                     else
  582.                     {
  583.                         WORD Offset = Size - Lines;
  584.  
  585.                         for(i = 0 ; i < Offset ; i++)
  586.                             ScrollLines[Start + i] = ScrollLines[Start + Lines + i];
  587.  
  588.                         for(i = Offset ; i < Size ; i++)
  589.                         {
  590.                             ScrollLines[Start + i] . Left        = 0;
  591.                             ScrollLines[Start + i] . Right        = LastColumn + 1;
  592.                             ScrollLines[Start + i] . ColourMask    = BackPen;
  593.                             ScrollLines[Start + i] . Width        = TextFontWidth;
  594.                         }
  595.                     }
  596.                 }
  597.             }
  598.         }
  599.         else
  600.         {
  601.             WORD    ScrollLineLeft    = 32767,
  602.                 ScrollLineRight    = 0,
  603.                 ScrollLineWidth    = 0;
  604.  
  605.             if(UseMasking)
  606.             {
  607.                 WORD i,Mask = 0;
  608.  
  609.                 for(i = Start ; i <= Stop ; i++)
  610.                 {
  611.                     if(ScrollLines[i] . Width)
  612.                     {
  613.                         if(ScrollLines[i] . Left < ScrollLineLeft)
  614.                             ScrollLineLeft = ScrollLines[i] . Left;
  615.  
  616.                         if(ScrollLines[i] . Right > ScrollLineRight)
  617.                             ScrollLineRight = ScrollLines[i] . Right;
  618.  
  619.                         if(ScrollLines[i] . Width > ScrollLineWidth)
  620.                             ScrollLineWidth = ScrollLines[i] . Width;
  621.  
  622.                         Mask |= ScrollLines[i] . ColourMask;
  623.                     }
  624.                 }
  625.  
  626.                 if(Mask)
  627.                     SetMask(RPort,Mask);
  628.                 else
  629.                 {
  630.                     if(ResetPen)
  631.                         SetBPen(RPort,BgPen);
  632.  
  633.                     return;
  634.                 }
  635.             }
  636.             else
  637.             {
  638.                 if(!DeltaX)
  639.                 {
  640.                     WORD i;
  641.  
  642.                     for(i = Start ; i <= Stop ; i++)
  643.                     {
  644.                         if(ScrollLines[i] . Width)
  645.                         {
  646.                             if(ScrollLines[i] . Left < ScrollLineLeft)
  647.                                 ScrollLineLeft = ScrollLines[i] . Left;
  648.  
  649.                             if(ScrollLines[i] . Right > ScrollLineRight)
  650.                                 ScrollLineRight = ScrollLines[i] . Right;
  651.  
  652.                             if(ScrollLines[i] . Width > ScrollLineWidth)
  653.                                 ScrollLineWidth = ScrollLines[i] . Width;
  654.                         }
  655.                     }
  656.                 }
  657.             }
  658.  
  659.             if(DeltaX)
  660.             {
  661.                 if(!ScrollLines[CursorY] . Width)
  662.                 {
  663.                     if(ResetPen)
  664.                         SetBPen(RPort,BgPen);
  665.  
  666.                     return;
  667.                 }
  668.                 else
  669.                 {
  670.                     WORD Last = (LastPixel + 1) / ScrollLines[CursorY] . Width;
  671.  
  672.                     if(DeltaX > 0)
  673.                         ScrollLines[CursorY] . Left -= DeltaX / ScrollLines[CursorY] . Width;
  674.                     else
  675.                         ScrollLines[CursorY] . Right -= DeltaX / ScrollLines[CursorY] . Width;
  676.  
  677.                     if(ScrollLines[CursorY] . Right < 0)
  678.                         ScrollLines[CursorY] . Right = 0;
  679.                     else
  680.                     {
  681.                         if(ScrollLines[CursorY] . Right > Last)
  682.                             ScrollLines[CursorY] . Right = Last;
  683.                     }
  684.  
  685.                     if(ScrollLines[CursorY] . Left < 0)
  686.                         ScrollLines[CursorY] . Left = 0;
  687.                     else
  688.                     {
  689.                         if(ScrollLines[CursorY] . Left > Last)
  690.                             ScrollLines[CursorY] . Left = Last;
  691.                     }
  692.                 }
  693.             }
  694.             else
  695.             {
  696.                 WORD    i,Lines,Size;
  697.  
  698.                 Lines    = DeltaY / TextFontHeight;
  699.                 Size    = (MaxY - MinY + 1) / TextFontHeight;
  700.  
  701.                 if(Lines < 0)
  702.                 {
  703.                     Lines = -Lines;
  704.  
  705.                     if(Size <= Lines)
  706.                     {
  707.                         for(i = 0 ; i < Size ; i++)
  708.                         {
  709.                             ScrollLines[Start + i] . Left        = 32767;
  710.                             ScrollLines[Start + i] . Right        = 0;
  711.                             ScrollLines[Start + i] . ColourMask    = 0;
  712.                             ScrollLines[Start + i] . Width        = 0;
  713.                         }
  714.                     }
  715.                     else
  716.                     {
  717.                         WORD Offset = Size - Lines;
  718.  
  719.                         for(i = 1 ; i <= Offset ; i++)
  720.                             ScrollLines[Start + Size - i] = ScrollLines[Start + Size - (i + Lines)];
  721.  
  722.                         for(i = 0 ; i < Lines ; i++)
  723.                         {
  724.                             ScrollLines[Start + i] . Left        = 32767;
  725.                             ScrollLines[Start + i] . Right        = 0;
  726.                             ScrollLines[Start + i] . ColourMask    = 0;
  727.                             ScrollLines[Start + i] . Width        = 0;
  728.                         }
  729.                     }
  730.                 }
  731.                 else
  732.                 {
  733.                     if(Size <= Lines)
  734.                     {
  735.                         for(i = 0 ; i < Size ; i++)
  736.                         {
  737.                             ScrollLines[Start + i] . Left        = 32767;
  738.                             ScrollLines[Start + i] . Right        = 0;
  739.                             ScrollLines[Start + i] . ColourMask    = 0;
  740.                             ScrollLines[Start + i] . Width        = 0;
  741.                         }
  742.                     }
  743.                     else
  744.                     {
  745.                         WORD Offset = Size - Lines;
  746.  
  747.                         for(i = 0 ; i < Offset ; i++)
  748.                             ScrollLines[Start + i] = ScrollLines[Start + Lines + i];
  749.  
  750.                         for(i = Offset ; i < Size ; i++)
  751.                         {
  752.                             ScrollLines[Start + i] . Left        = 32767;
  753.                             ScrollLines[Start + i] . Right        = 0;
  754.                             ScrollLines[Start + i] . ColourMask    = 0;
  755.                             ScrollLines[Start + i] . Width        = 0;
  756.                         }
  757.                     }
  758.                 }
  759.  
  760.                 if(ScrollLineWidth)
  761.                 {
  762.                     WORD Temp;
  763.  
  764.                     if((Temp = ScrollLineLeft * ScrollLineWidth) > MinX)
  765.                         MinX = Temp;
  766.  
  767.                     if((Temp = ScrollLineRight * ScrollLineWidth) < MaxX)
  768.                         MaxX = Temp;
  769.  
  770.                     if(MaxX == ScrollLineRight)
  771.                         MaxX += FontRightExtend;    // Add margin for italics or boldface.
  772.  
  773.                     if(DeltaY < 0)
  774.                     {
  775.                         if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  776.                             MinY = Temp;
  777.  
  778.                         if((Temp = MUL_Y(ScrollLineLast + 1) - 1 - DeltaY) < MaxY)
  779.                             MaxY = Temp;
  780.                     }
  781.                     else
  782.                     {
  783.                         if(DeltaY > 0)
  784.                         {
  785.                             if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
  786.                                 MinY = Temp;
  787.  
  788.                             if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  789.                                 MaxY = Temp;
  790.                         }
  791.                     }
  792.  
  793.                     if(MinX < 0)
  794.                         MinX = 0;
  795.  
  796.                     if(MaxX < 0)
  797.                         MaxX = 0;
  798.  
  799.                     if(MinY < 0)
  800.                         MinY = 0;
  801.  
  802.                     if(MaxY < 0)
  803.                         MaxY = 0;
  804.                 }
  805.                 else
  806.                 {
  807.                     ScrollFrameUpdate();
  808.  
  809.                     if(ResetPen)
  810.                         SetBPen(RPort,BgPen);
  811.  
  812.                     return;
  813.                 }
  814.             }
  815.         }
  816.  
  817.         if(Start < ScrollLineFirst)
  818.             ScrollLineFirst = Start;
  819.  
  820.         if(Stop > ScrollLineLast)
  821.             ScrollLineLast = Stop;
  822.  
  823.         ScrollFrameUpdate();
  824.  
  825.         if(MinX < MaxX && MinY < MaxY)
  826.         {
  827.             MinX += WindowLeft;
  828.             MaxX += WindowLeft;
  829.  
  830.             MinY += WindowTop;
  831.             MaxY += WindowTop;
  832.  
  833.                 /* Smooth scrolling requested? */
  834.  
  835.             if(Smooth && DeltaY)
  836.             {
  837.                 WORD Lines,Extra,Direction;
  838.  
  839.                 Lines = ABS(DeltaY);
  840.                 Extra = Lines & 1;
  841.                 Lines = Lines / 2;
  842.  
  843.                 if(DeltaY > 0)
  844.                     Direction = 2;
  845.                 else
  846.                     Direction = -2;
  847.  
  848.                 while(Lines-- > 0)
  849.                 {
  850.                     WaitBlit();
  851.                     WaitTOF();
  852.                     ScrollRaster(RPort,0,Direction,MinX,MinY,MaxX,MaxY);
  853.                 }
  854.  
  855.                 if(Extra)
  856.                 {
  857.                     WaitBlit();
  858.                     WaitTOF();
  859.                     ScrollRaster(RPort,0,Direction / 2,MinX,MinY,MaxX,MaxY);
  860.                 }
  861.             }
  862.             else
  863.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  864.         }
  865.  
  866.         if(ResetPen)
  867.             SetBPen(RPort,BgPen);
  868.     }
  869.  
  870. //    DebugShowScrollInfo();
  871. #endif
  872. }
  873.  
  874. VOID __regargs
  875. ScrollLineRasterNoTabChange(struct RastPort *RPort,WORD DeltaX,WORD DeltaY,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY,BYTE Smooth)
  876. {
  877. #ifdef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  878.     if((DeltaX || DeltaY) && MinX < MaxX && MinY < MaxY)
  879.     {
  880.         MinX += WindowLeft;
  881.         MinY += WindowTop;
  882.         MaxX += WindowLeft;
  883.         MaxY += WindowTop;
  884.  
  885.         if(Smooth && DeltaY)
  886.         {
  887.             WORD Count,Direction,Extra;
  888.             BOOL ResetPen;
  889.  
  890.             if(DeltaY < 0)
  891.             {
  892.                 Count        = -DeltaY;
  893.                 Direction    = -2;
  894.             }
  895.             else
  896.             {
  897.                 Count        = DeltaY;
  898.                 Direction    = 2;
  899.             }
  900.  
  901.             Extra = Count & 1;
  902.             Count = Count / 2;
  903.  
  904.             if((Attributes & ATTR_INVERSE) && (FgPen != BgPen))
  905.             {
  906.                 SetBPen(RPort,FgPen);
  907.  
  908.                 ResetPen = TRUE;
  909.             }
  910.             else
  911.                 ResetPen = FALSE;
  912.  
  913.             while(Count--)
  914.             {
  915.                 WaitBlit();
  916.                 WaitTOF();
  917.                 ScrollRaster(RPort,0,Direction,MinX,MinY,MaxX,MaxY);
  918.             }
  919.  
  920.             if(Extra)
  921.             {
  922.                 WaitBlit();
  923.                 WaitTOF();
  924.                 ScrollRaster(RPort,0,Direction / 2,MinX,MinY,MaxX,MaxY);
  925.             }
  926.  
  927.             if(ResetPen)
  928.                 SetBPen(RPort,BgPen);
  929.         }
  930.         else
  931.         {
  932.             if((Attributes & ATTR_INVERSE) && (FgPen != BgPen))
  933.             {
  934.                 SetBPen(RPort,FgPen);
  935.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  936.                 SetBPen(RPort,BgPen);
  937.             }
  938.             else
  939.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  940.         }
  941.     }
  942. #else
  943.     if((DeltaX || DeltaY) && MinX < MaxX && MinY < MaxY)
  944.     {
  945.         WORD    Start,Stop;
  946.         WORD    BackPen;
  947.         BOOL    ResetPen;
  948.  
  949.         if((Attributes & ATTR_INVERSE) && (FgPen != BgPen))
  950.         {
  951.             SetBPen(RPort,FgPen);
  952.  
  953.             ResetPen    = TRUE;
  954.             BackPen        = FgPen;
  955.         }
  956.         else
  957.         {
  958.             ResetPen    = FALSE;
  959.             BackPen        = BgPen;
  960.         }
  961.  
  962.         Start    = MinY / TextFontHeight;
  963.         Stop    = MaxY / TextFontHeight;
  964.  
  965.         if(BackPen)
  966.         {
  967.             if(UseMasking)
  968.             {
  969.                 WORD i,Mask = BackPen;
  970.  
  971.                 for(i = Start ; i <= Stop ; i++)
  972.                 {
  973.                     if(ScrollLines[i] . Width)
  974.                         Mask |= ScrollLines[i] . ColourMask;
  975.                 }
  976.  
  977.                 SetMask(RPort,Mask);
  978.             }
  979.  
  980.             if(DeltaX)
  981.             {
  982.                 if(!ScrollLines[CursorY] . Width)
  983.                 {
  984.                     if(ResetPen)
  985.                         SetBPen(RPort,BgPen);
  986.  
  987.                     return;
  988.                 }
  989.             }
  990.         }
  991.         else
  992.         {
  993.             WORD    ScrollLineLeft    = 32767,
  994.                 ScrollLineRight    = 0,
  995.                 ScrollLineWidth    = 0;
  996.  
  997.             if(UseMasking)
  998.             {
  999.                 WORD i,Mask = 0;
  1000.  
  1001.                 for(i = Start ; i <= Stop ; i++)
  1002.                 {
  1003.                     if(ScrollLines[i] . Width)
  1004.                     {
  1005.                         if(ScrollLines[i] . Left < ScrollLineLeft)
  1006.                             ScrollLineLeft = ScrollLines[i] . Left;
  1007.  
  1008.                         if(ScrollLines[i] . Right > ScrollLineRight)
  1009.                             ScrollLineRight = ScrollLines[i] . Right;
  1010.  
  1011.                         if(ScrollLines[i] . Width > ScrollLineWidth)
  1012.                             ScrollLineWidth = ScrollLines[i] . Width;
  1013.  
  1014.                         Mask |= ScrollLines[i] . ColourMask;
  1015.                     }
  1016.                 }
  1017.  
  1018.                 if(Mask)
  1019.                     SetMask(RPort,Mask);
  1020.                 else
  1021.                 {
  1022.                     if(ResetPen)
  1023.                         SetBPen(RPort,BgPen);
  1024.  
  1025.                     return;
  1026.                 }
  1027.             }
  1028.             else
  1029.             {
  1030.                 if(!DeltaX)
  1031.                 {
  1032.                     WORD i;
  1033.  
  1034.                     for(i = Start ; i <= Stop ; i++)
  1035.                     {
  1036.                         if(ScrollLines[i] . Width)
  1037.                         {
  1038.                             if(ScrollLines[i] . Left < ScrollLineLeft)
  1039.                                 ScrollLineLeft = ScrollLines[i] . Left;
  1040.  
  1041.                             if(ScrollLines[i] . Right > ScrollLineRight)
  1042.                                 ScrollLineRight = ScrollLines[i] . Right;
  1043.  
  1044.                             if(ScrollLines[i] . Width > ScrollLineWidth)
  1045.                                 ScrollLineWidth = ScrollLines[i] . Width;
  1046.                         }
  1047.                     }
  1048.                 }
  1049.             }
  1050.  
  1051.             if(DeltaX)
  1052.             {
  1053.                 if(!ScrollLines[CursorY] . Width)
  1054.                 {
  1055.                     if(ResetPen)
  1056.                         SetBPen(RPort,BgPen);
  1057.  
  1058.                     return;
  1059.                 }
  1060.             }
  1061.             else
  1062.             {
  1063.                 if(ScrollLineWidth)
  1064.                 {
  1065.                     WORD Temp;
  1066.  
  1067.                     if((Temp = ScrollLineLeft * ScrollLineWidth) > MinX)
  1068.                         MinX = Temp;
  1069.  
  1070.                     if((Temp = ScrollLineRight * ScrollLineWidth) < MaxX)
  1071.                         MaxX = Temp;
  1072.  
  1073.                     if(MaxX == ScrollLineRight)
  1074.                         MaxX += FontRightExtend;    // Add margin for italics or boldface.
  1075.  
  1076.                     if(DeltaY < 0)
  1077.                     {
  1078.                         if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  1079.                             MinY = Temp;
  1080.  
  1081.                         if((Temp = MUL_Y(ScrollLineLast + 1) - 1 - DeltaY) < MaxY)
  1082.                             MaxY = Temp;
  1083.                     }
  1084.                     else
  1085.                     {
  1086.                         if(DeltaY > 0)
  1087.                         {
  1088.                             if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
  1089.                                 MinY = Temp;
  1090.  
  1091.                             if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  1092.                                 MaxY = Temp;
  1093.                         }
  1094.                     }
  1095.  
  1096.                     if(MinX < 0)
  1097.                         MinX = 0;
  1098.  
  1099.                     if(MaxX < 0)
  1100.                         MaxX = 0;
  1101.  
  1102.                     if(MinY < 0)
  1103.                         MinY = 0;
  1104.  
  1105.                     if(MaxY < 0)
  1106.                         MaxY = 0;
  1107.                 }
  1108.                 else
  1109.                 {
  1110.                     ScrollFrameUpdate();
  1111.  
  1112.                     if(ResetPen)
  1113.                         SetBPen(RPort,BgPen);
  1114.  
  1115.                     return;
  1116.                 }
  1117.             }
  1118.         }
  1119.  
  1120.         if(Start < ScrollLineFirst)
  1121.             ScrollLineFirst = Start;
  1122.  
  1123.         if(Stop > ScrollLineLast)
  1124.             ScrollLineLast = Stop;
  1125.  
  1126.         ScrollFrameUpdate();
  1127.  
  1128.         if(MinX < MaxX && MinY < MaxY)
  1129.         {
  1130.             MinX += WindowLeft;
  1131.             MaxX += WindowLeft;
  1132.  
  1133.             MinY += WindowTop;
  1134.             MaxY += WindowTop;
  1135.  
  1136.                 /* Smooth scrolling requested? */
  1137.  
  1138.             if(Smooth && DeltaY)
  1139.             {
  1140.                 WORD Lines,Extra,Direction;
  1141.  
  1142.                 Lines = ABS(DeltaY);
  1143.                 Extra = Lines & 1;
  1144.                 Lines = Lines / 2;
  1145.  
  1146.                 if(DeltaY > 0)
  1147.                     Direction = 2;
  1148.                 else
  1149.                     Direction = -2;
  1150.  
  1151.                 while(Lines-- > 0)
  1152.                 {
  1153.                     WaitBlit();
  1154.                     WaitTOF();
  1155.                     ScrollRaster(RPort,0,Direction,MinX,MinY,MaxX,MaxY);
  1156.                 }
  1157.  
  1158.                 if(Extra)
  1159.                 {
  1160.                     WaitBlit();
  1161.                     WaitTOF();
  1162.                     ScrollRaster(RPort,0,Direction / 2,MinX,MinY,MaxX,MaxY);
  1163.                 }
  1164.             }
  1165.             else
  1166.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  1167.         }
  1168.  
  1169.         if(ResetPen)
  1170.             SetBPen(RPort,BgPen);
  1171.     }
  1172.  
  1173. //    DebugShowScrollInfo();
  1174. #endif
  1175. }
  1176.  
  1177.     /* ScrollLineEraseScreen(BYTE Mode):
  1178.      *
  1179.      *    Erase a part of the screen.
  1180.      */
  1181.  
  1182. VOID __regargs
  1183. ScrollLineEraseScreen(BYTE Mode)
  1184. {
  1185. #ifndef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  1186.     WORD i;
  1187.  
  1188.     if(BgPen)
  1189.     {
  1190.         switch(Mode)
  1191.         {
  1192.                 /* Erase from first line to current cursor position (inclusive). */
  1193.  
  1194.             case 1:    ScrollLineFirst = CursorY;
  1195.  
  1196.                 if(ScrollLineLast < CursorY)
  1197.                     ScrollLineLast = CursorY;
  1198.  
  1199.                     /* Reset the lines. */
  1200.  
  1201.                 for(i = 0 ; i < CursorY ; i++)
  1202.                 {
  1203.                     ScrollLines[i] . Left        = 0;
  1204.                     ScrollLines[i] . Right        = LastColumn + 1;
  1205.                     ScrollLines[i] . ColourMask    = BgPen;
  1206.                     ScrollLines[i] . Width        = TextFontWidth;
  1207.                 }
  1208.  
  1209.                 if(CursorX)
  1210.                 {
  1211.                     if(!ScrollLines[CursorY] . Width)
  1212.                         ScrollLines[CursorY] . Width = GetFontWidth();
  1213.  
  1214.                     ScrollLines[CursorY] . Left        = 0;
  1215.                     ScrollLines[CursorY] . ColourMask    |= BgPen;
  1216.                 }
  1217.  
  1218.                 break;
  1219.  
  1220.                 /* Erase entire screen. */
  1221.  
  1222.             case 2:    for(i = 0 ; i < RasterHeight ; i++)
  1223.                 {
  1224.                     ScrollLines[i] . Left        = 0;
  1225.                     ScrollLines[i] . Right        = LastColumn + 1;
  1226.                     ScrollLines[i] . ColourMask    = BgPen;
  1227.                     ScrollLines[i] . Width        = TextFontWidth;
  1228.                 }
  1229.  
  1230.                 ScrollLineFirst    = 0;
  1231.                 ScrollLineLast    = RasterHeight - 1;
  1232.  
  1233.                 break;
  1234.  
  1235.                 /* Erase from current cursor position to end of screen. */
  1236.  
  1237.             default:for(i = CursorY + 1 ; i < RasterHeight ; i++)
  1238.                 {
  1239.                     ScrollLines[i] . Left        = 0;
  1240.                     ScrollLines[i] . Right        = LastColumn + 1;
  1241.                     ScrollLines[i] . ColourMask    = BgPen;
  1242.                     ScrollLines[i] . Width        = TextFontWidth;
  1243.                 }
  1244.  
  1245.                 if(!ScrollLines[CursorY] . Width)
  1246.                     ScrollLines[CursorY] . Width = GetFontWidth();
  1247.  
  1248.                 ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
  1249.  
  1250.                 if(CursorX)
  1251.                     ScrollLines[CursorY] . ColourMask |= BgPen;
  1252.                 else
  1253.                     ScrollLines[CursorY] . ColourMask = BgPen;
  1254.  
  1255.                 if(ScrollLineFirst > CursorY)
  1256.                     ScrollLineFirst = CursorY;
  1257.  
  1258.                 ScrollLineLast = RasterHeight - 1;
  1259.  
  1260.                 break;
  1261.         }
  1262.     }
  1263.     else
  1264.     {
  1265.         switch(Mode)
  1266.         {
  1267.                 /* Erase from first line to current cursor line (inclusive). */
  1268.  
  1269.             case 1:        /* Reset the lines. */
  1270.  
  1271.                 for(i = 0 ; i < CursorY ; i++)
  1272.                 {
  1273.                     ScrollLines[i] . Left        = 32767;
  1274.                     ScrollLines[i] . Right        = 0;
  1275.                     ScrollLines[i] . ColourMask    = 0;
  1276.                     ScrollLines[i] . Width        = 0;
  1277.                 }
  1278.  
  1279.                 ScrollLines[CursorY] . Left = CursorX;
  1280.  
  1281.                 if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
  1282.                 {
  1283.                     ScrollLines[CursorY] . Left    = 32767;
  1284.                     ScrollLines[CursorY] . Right    = 0;
  1285.                     ScrollLines[CursorY] . Width    = 0;
  1286.  
  1287.                         /* Cleared the entire screen? */
  1288.  
  1289.                     if(CursorY == RasterHeight - 1)
  1290.                     {
  1291.                         ScrollLineFirst    = 32767;
  1292.                         ScrollLineLast    = 0;
  1293.                     }
  1294.                     else
  1295.                         ScrollLineFirst = CursorY;
  1296.                 }
  1297.                 else
  1298.                     ScrollLineFirst = CursorY;
  1299.  
  1300.                 if(ScrollLineLast < CursorY)
  1301.                     ScrollLineLast = CursorY;
  1302.  
  1303.                 break;
  1304.  
  1305.                 /* Erase entire screen. */
  1306.  
  1307.             case 2:    for(i = 0 ; i < RasterHeight ; i++)
  1308.                 {
  1309.                     ScrollLines[i] . Left        = 32767;
  1310.                     ScrollLines[i] . Right        = 0;
  1311.                     ScrollLines[i] . ColourMask    = 0;
  1312.                     ScrollLines[i] . Width        = 0;
  1313.                 }
  1314.  
  1315.                 ScrollLineFirst    = 32767;
  1316.                 ScrollLineLast    = 0;
  1317.  
  1318.                 break;
  1319.  
  1320.                 /* Erase from current cursor position to end of screen. */
  1321.  
  1322.             default:for(i = CursorY + 1 ; i < RasterHeight ; i++)
  1323.                 {
  1324.                     ScrollLines[i] . Left        = 32767;
  1325.                     ScrollLines[i] . Right        = 0;
  1326.                     ScrollLines[i] . ColourMask    = 0;
  1327.                     ScrollLines[i] . Width        = 0;
  1328.                 }
  1329.  
  1330.                 if(CursorX)
  1331.                 {
  1332.                     ScrollLines[CursorY] . Right = CursorX;
  1333.  
  1334.                     if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
  1335.                     {
  1336.                         ScrollLines[CursorY] . Left    = 32767;
  1337.                         ScrollLines[CursorY] . Right    = 0;
  1338.                         ScrollLines[CursorY] . Width    = 0;
  1339.                     }
  1340.                 }
  1341.                 else
  1342.                 {
  1343.                     ScrollLines[CursorY] . Left    = 32767;
  1344.                     ScrollLines[CursorY] . Right    = 0;
  1345.                     ScrollLines[CursorY] . Width    = 0;
  1346.                 }
  1347.  
  1348.                 /* Cleared the entire screen? */
  1349.  
  1350.                 if(CursorY)
  1351.                     ScrollLineLast = CursorY;
  1352.                 else
  1353.                 {
  1354.                     if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
  1355.                     {
  1356.                         ScrollLineFirst    = 32767;
  1357.                         ScrollLineLast    = 0;
  1358.                     }
  1359.                     else
  1360.                     {
  1361.                         if(ScrollLineFirst > CursorY)
  1362.                             ScrollLineFirst = CursorY;
  1363.                     }
  1364.                 }
  1365.  
  1366.                 break;
  1367.         }
  1368.     }
  1369.  
  1370.     ScrollFrameUpdate();
  1371.  
  1372. //    DebugShowScrollInfo();
  1373. #endif
  1374. }
  1375.  
  1376.     /* ScrollLineEraseLine(BYTE Mode):
  1377.      *
  1378.      *    Erase parts of the current cursor line.
  1379.      */
  1380.  
  1381. VOID __regargs
  1382. ScrollLineEraseLine(BYTE Mode)
  1383. {
  1384. #ifndef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  1385.     if(BgPen)
  1386.     {
  1387.         switch(Mode)
  1388.         {
  1389.                 /* Erase from left margin to current cursor position (inclusive). */
  1390.  
  1391.             case 1:    ScrollLines[CursorY] . Left = 0;
  1392.  
  1393.                 ScrollLines[CursorY] . ColourMask |= BgPen;
  1394.  
  1395.                 if(!ScrollLines[CursorY] . Width)
  1396.                     ScrollLines[CursorY] . Width = GetFontWidth();
  1397.  
  1398.                 break;
  1399.  
  1400.                 /* Erase entire line. */
  1401.  
  1402.             case 2:    ScrollLines[CursorY] . Width        = GetFontWidth();
  1403.                 ScrollLines[CursorY] . Left        = 0;
  1404.                 ScrollLines[CursorY] . Right        = (LastPixel + 1) / ScrollLines[CursorY] . Width;
  1405.                 ScrollLines[CursorY] . ColourMask    = BgPen;
  1406.  
  1407.                 break;
  1408.  
  1409.                 /* Erase from current cursor position towards end of line. */
  1410.  
  1411.             default:if(CursorX)
  1412.                 {
  1413.                     if(!ScrollLines[CursorY] . Width)
  1414.                         ScrollLines[CursorY] . Width = GetFontWidth();
  1415.  
  1416.                     ScrollLines[CursorY] . ColourMask |= BgPen;
  1417.                 }
  1418.                 else
  1419.                 {
  1420.                     ScrollLines[CursorY] . Width        = GetFontWidth();
  1421.                     ScrollLines[CursorY] . Left        = 0;
  1422.                     ScrollLines[CursorY] . ColourMask    = BgPen;
  1423.                 }
  1424.  
  1425.                 ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
  1426.                 break;
  1427.         }
  1428.     }
  1429.     else
  1430.     {
  1431.         switch(Mode)
  1432.         {
  1433.                 /* Erase from left margin to current cursor position (inclusive). */
  1434.  
  1435.             case 1:    ScrollLines[CursorY] . Left = CursorX;
  1436.  
  1437.                 if(ScrollLines[CursorY] . Left >= ScrollLines[CursorY] . Right)
  1438.                 {
  1439.                     ScrollLines[CursorY] . Left    = 32767;
  1440.                     ScrollLines[CursorY] . Right    = 0;
  1441.                     ScrollLines[CursorY] . Width    = 0;
  1442.                 }
  1443.  
  1444.                 break;
  1445.  
  1446.                 /* Erase entire line. */
  1447.  
  1448.             case 2:    ScrollLines[CursorY] . Left    = 32767;
  1449.                 ScrollLines[CursorY] . Right    = 0;
  1450.                 ScrollLines[CursorY] . Width    = 0;
  1451.  
  1452.                 break;
  1453.  
  1454.                 /* Erase from current cursor position towards end of line. */
  1455.  
  1456.             default:if(CursorX)
  1457.                     ScrollLines[CursorY] . Right = CursorX;
  1458.                 else
  1459.                 {
  1460.                     ScrollLines[CursorY] . Left    = 32767;
  1461.                     ScrollLines[CursorY] . Right    = 0;
  1462.                     ScrollLines[CursorY] . Width    = 0;
  1463.                 }
  1464.  
  1465.                 break;
  1466.         }
  1467.     }
  1468.  
  1469.     ScrollFrameUpdate();
  1470.  
  1471. //    DebugShowScrollInfo();
  1472. #endif
  1473. }
  1474.  
  1475.     /* ScrollLineEraseCharacters(WORD Chars):
  1476.      *
  1477.      *    Erase a number of characters in the current cursor line.
  1478.      */
  1479.  
  1480. VOID __regargs
  1481. ScrollLineEraseCharacters(WORD Chars)
  1482. {
  1483. #ifndef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  1484.         /* Any characters to erase? */
  1485.  
  1486.     if(BgPen)
  1487.     {
  1488.         if(!ScrollLines[CursorY] . Width)
  1489.             ScrollLines[CursorY] . Width = GetFontWidth();
  1490.  
  1491.         ScrollLines[CursorY] . Left    = 0;
  1492.         ScrollLines[CursorY] . Right    = (LastPixel + 1) / ScrollLines[CursorY] . Width;
  1493.  
  1494.         ScrollLines[CursorY] . ColourMask |= BgPen;
  1495.     }
  1496.     else
  1497.     {
  1498.         if(ScrollLines[CursorY] . Right > Chars)
  1499.             ScrollLines[CursorY] . Right -= Chars;
  1500.         else
  1501.             ScrollLines[CursorY] . Right = 0;
  1502.     }
  1503.  
  1504. //    DebugShowScrollInfo();
  1505. #endif
  1506. }
  1507.  
  1508.     /* ScrollLineShiftChar(WORD Size):
  1509.      *
  1510.      *    Shift the characters following the current cursor position
  1511.      *    Size characters to the right.
  1512.      */
  1513.  
  1514. VOID __regargs
  1515. ScrollLineShiftChar(WORD Size)
  1516. {
  1517. #ifndef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  1518.         /* Any characters to scroll? */
  1519.  
  1520.     if(BgPen)
  1521.     {
  1522.         if(!ScrollLines[CursorY] . Width)
  1523.             ScrollLines[CursorY] . Width = GetFontWidth();
  1524.  
  1525.         ScrollLines[CursorY] . Left    = 0;
  1526.         ScrollLines[CursorY] . Right    = (LastPixel + 1) / ScrollLines[CursorY] . Width;
  1527.  
  1528.         ScrollLines[CursorY] . ColourMask |= BgPen;
  1529.     }
  1530.     else
  1531.     {
  1532.         WORD Temp;
  1533.  
  1534.         ScrollLines[CursorY] . Right += Size;
  1535.  
  1536.         if((Temp = ScrollLines[CursorY] . Right * ScrollLines[CursorY] . Width) > LastPixel)
  1537.             ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
  1538.         else
  1539.         {
  1540.             if(ScrollLines[CursorY] . Right < 0)
  1541.                 ScrollLines[CursorY] . Right = 0;
  1542.         }
  1543.     }
  1544.  
  1545. //    DebugShowScrollInfo();
  1546. #endif
  1547. }
  1548.  
  1549. //STATIC WORD LastY = 32767;
  1550.  
  1551.     /* ScrollLinePutString(WORD Length):
  1552.      *
  1553.      *    Update the line info according to the length of a string
  1554.      *    to be printed.
  1555.      */
  1556.  
  1557. VOID __regargs
  1558. ScrollLinePutString(WORD Length)
  1559. {
  1560. #ifndef WHO_CARES_ABOUT_THIS_STUFF_ANYWAY
  1561.     if(Length)
  1562.     {
  1563.         LONG Width;
  1564.  
  1565.             /* Which scale is the font we are currently using? */
  1566.  
  1567.         if(RasterAttr[CursorY] >= SCALE_ATTR_TOP2X)
  1568.         {
  1569.                 /* Valid length? */
  1570.  
  1571.             if(CursorX + Length >= RasterWidth / 2)
  1572.                 Length = (RasterWidth / 2) - CursorX;
  1573.  
  1574.                 /* Double width. */
  1575.  
  1576.             Width = TextFontWidth * 2;
  1577.         }
  1578.         else
  1579.         {
  1580.             if(CurrentCharWidth == SCALE_HALF)
  1581.             {
  1582.                     /* Valid length? */
  1583.  
  1584.                 if(CursorX + Length >= RasterWidth * 2)
  1585.                     Length = (RasterWidth * 2) - CursorX;
  1586.  
  1587.                     /* Half width. */
  1588.  
  1589.                 Width = TextFontWidth / 2;
  1590.             }
  1591.             else
  1592.             {
  1593.                     /* Valid length? */
  1594.  
  1595.                 if(CursorX + Length >= RasterWidth)
  1596.                     Length = RasterWidth - CursorX;
  1597.  
  1598.                     /* Normal width. */
  1599.  
  1600.                 Width = TextFontWidth;
  1601.             }
  1602.         }
  1603.  
  1604.             /* Sensible value? */
  1605.  
  1606.         if(Length > 0)
  1607.         {
  1608.             struct ScrollLineInfo *Alias = &ScrollLines[CursorY];
  1609.  
  1610.                 /* Update font scale. */
  1611.  
  1612.             Alias -> Width = Width;
  1613.  
  1614.                 /* Update right margin. */
  1615.  
  1616.             if(CursorX < Alias -> Left)
  1617.                 Alias -> Left = CursorX;
  1618.  
  1619.                 /* Update left margin. */
  1620.  
  1621.             if(CursorX + Length > Alias -> Right)
  1622.                 Alias -> Right = CursorX + Length;
  1623.  
  1624.                 /* Update topmost line. */
  1625.  
  1626.             if(CursorY < ScrollLineFirst)
  1627.                 ScrollLineFirst = CursorY;
  1628.  
  1629.                 /* Update bottommost line. */
  1630.  
  1631.             if(CursorY > ScrollLineLast)
  1632.                 ScrollLineLast = CursorY;
  1633.  
  1634.             if(UseMasking)
  1635.             {
  1636.                     /* Update line colour mask. */
  1637.  
  1638.                 Alias -> ColourMask |= FgPen | BgPen;
  1639.  
  1640.                     /* Set write mask (will affect Text() since it is called
  1641.                      * after this routine has finished.
  1642.                      */
  1643.  
  1644.                 SetMask(RPort,Alias -> ColourMask);
  1645.             }
  1646. /*
  1647.             if(CursorY != LastY)
  1648.             {
  1649.                 LastY = CursorY;
  1650.                 DebugShowScrollInfo();
  1651.             }
  1652. */
  1653.         }
  1654.     }
  1655. #endif
  1656. }
  1657.